package com.king.zxing.app;

import android.Manifest;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

import com.king.zxing.app.util.GenerateQrCodeUtil;

import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

public class GenerateCodeActivity extends Activity {

    private EditText inputContent;
    private EditText inputname;
    private String content;
    private String contentname;
    public static final int RC_READ_PHOTO = 0X02;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_generate);
        checkExternalStoragePermissions();
        this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window = getWindow();
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            if (window != null) {
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            }
        }
        inputContent = findViewById(R.id.barcode_content);
        inputname = findViewById(R.id.barcode_contentname1);
    }

    /**
     * 检查是否有存储权限
     */
    @AfterPermissionGranted(RC_READ_PHOTO)
    private void checkExternalStoragePermissions(){
        String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE};
        if (EasyPermissions.hasPermissions(this, perms)) {//有权限

        }else{
            EasyPermissions.requestPermissions(this, getString(R.string.permission_external_storage),
                    RC_READ_PHOTO, perms);
        }
    }

    public void generateCodeBtnClick(View v) {

        contentname = inputname.getText().toString();
        content =inputContent.getText().toString();
        GenerateQrCodeUtil.generateQrcode(GenerateCodeActivity.this,contentname,content);
    }



    /*public void showViewClick(View v) {
                Intent intent = new Intent(GenerateCodeActivity.this,ShowViewActivity.class);
                startActivity(intent);
            }*/
}